<?php

namespace Library\Prizes;

/**
 * 
 *
 * @author pufan
 */
class Ad extends Prizes{
    
    public function __construct($desc) {
        parent::__construct($desc);
        $this->desc['type'] = Prizes::AD;
        $this->init_order();
    }
    
    protected function save_order() {
        $data['card_type'] = 4;
        $data['event_id'] = $this->get_order_attr('event_id');
        $data['openid'] = $this->get_order_attr('openid');
        $data['userid'] = $_SESSION['user_id'];
        $data['order_status'] = 0;
        $data['card_num'] = 1;  //卡券数量
        $data['winning_time'] = $this->winning_time;  //
        $data['sn_number'] = $this->sn_number;  //

        \Think\Log::record('ad: save_order: '. json_encode($data).' openid: '.$_SESSION['open_id']);
        $this->card_model->where('id='.$this->get_order_attr('card_id'))->setInc('card_get_count');
        //暂时去掉对当前用户广告展示次数的限制
        //$this->update_user_prizes_count($this->get_order_attr('card_id'), $this->get_order_attr('openid'));
    }

    public function get_view_desc() {
        $data['title'] = $this->get_order_attr('title');
        $data['center_pic'] = $this->get_order_attr('center_pic'); 
        $data['center_url'] = $this->create_analytics_url();
        \Think\Log::record('get_view_desc', json_encode($data));
        return $data;
    }
}
